<?php
namespace Admin\Controller;
use Think\Controller;
class UserController extends Controller {
    public function index(){
       echo"hello word!";
    }
    //编写函数。获取用户表数据
    public function userlist(){
      //调用模型层操作数据
		$usersmodel=M('users');

		$users=$usersmodel->order('id desc')->select();
		$this->users=$users;
		//调用视图层显示结果
		$this->display();
	}
	public function deluser($id){
		$usersmodel=M('users');
		if (false!==$usersmodel->where("id=$id")->delete()){
			$this->success('删除成功！');
		}else{
			$this->error('删除失败');
		}
	}
     public function editpswd($id){
	        $usersmodel=M('users');
	        $usersmodel->password="123456";
		 if(false!==$usersmodel->where("id=$id")->save()){
			 $this->success('密码重置成功');
		 }else{
			 $this->error('密码重置失败');
		 }
        }
	public function editstate($id,$state){
		$usersmodel=M('users');

		$usersmodel->state=(1+$state)%2;
		/*echo"$usersmodel->state";*/
		if(false!==$usersmodel->where("id=$id")->save()){
			$this->success('设置成功');
		}else{
			$this->error('设置失败');
		}
	}
	public function edituser($id){
		$usersmodel=M('users');
		$usersmodel->create();
		$usersmodel->save();
	}
	public function usermod($id){
		$usersmodel=M('users');
		$data = $usersmodel->where("id=$id")->select();
		$this->users=$data;
		$this->display();
	}
}